uniform extern texture ScreenTexture;
uniform extern float2 PlayerPosition;
uniform extern float PlayerLookAngle;
uniform extern float AspectRatio;

sampler ScreenS = sampler_state
{
    Texture = <ScreenTexture>;    
};

float4 Fog(float2 coord: TEXCOORD0) : COLOR
{
	float yDiff = coord.y - PlayerPosition.y;
	float xDiff = (coord.x - PlayerPosition.x) * AspectRatio;
	float angle = atan2(xDiff, yDiff);
	float twoPi = 2*3.14159;
	float angleDiff = min(min(abs(PlayerLookAngle - angle + twoPi), abs(PlayerLookAngle - angle)), abs(PlayerLookAngle - angle - twoPi));

	float dist = distance(float2(coord.x * AspectRatio, coord.y), float2(PlayerPosition.x * AspectRatio, PlayerPosition.y));
	
	return float4(0.0, 0.0, 0.0, 1 - max(0, (1-angleDiff-2*dist)) - max(0, (1-6*dist)/3));
}

technique Colorize
{
    pass ColorTransform
    {
        PixelShader = compile ps_2_0 Fog();
    }
}
